/*
 * Copyright © 2015-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shiro.tutorials;

/**
 * 自定义异常
 * @author WD
 * @since  0.0.1
 */
public class CustomException {

/**
 * .
 * @param args args
 */
public static void main(String[] args) {
    Math math = new Math();
    try {
        math.divide(3, 0);
    } catch (DivisorNegativeException e) {
        System.out.println(e.getMessage()); 
        e.printStackTrace();
    } catch (DivisorZeroException e) {
        System.out.println(e.getMessage()); 
        e.printStackTrace();
    }
}

}
/**
 * 除数为负.
 *
 * @author WD
 * @since  0.0.1
 */
class DivisorNegativeException extends Exception {
    
    /**
     * 
     */
    private static final long serialVersionUID = 7964376773258517060L;

    public DivisorNegativeException (String message) {
        super(message);
    }
}
/**
 * 除数为0.
 *
 * @author WD
 * @since  0.0.1
 */
class DivisorZeroException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = -1091515098127780093L;
    public DivisorZeroException (String message) {
        super(message);
    }
}
/**
 * 运算
 *
 * @author WD
 * @since  0.0.1
 */
class Math {
    /**
     * divide.
     * @param x
     * @param y
     * @return x/y
     * @throws DivisorNegativeException
     * @throws DivisorZeroException
     */
    public int divide(int x, int y) throws DivisorNegativeException,DivisorZeroException {
        if (y < 0) {
            throw new DivisorNegativeException("除数不可小于0");
        }
        if (y == 0) {
            throw new DivisorZeroException("除数不可为0");
        }
        return x/y;
    }
}